var Grid = require("MapGrid");
var GameOption = require("GameOption");
var Ini = require("Initiate");

cc.Class({
    extends: cc.Component,

    properties: {
        Option:{
            default: null,
            type: GameOption
        },
        Grid:{
            default: null,
            type: Grid
        },
        Menu:{
            default: null,
            type: cc.Node
        },
        Player:{
            default:null,
            type: cc.Node
        },
        Initiate:{
            default: null,
            type:Ini
        },         
        GameStart:false,      
        HP:10,
        HPUI: {
            default: null,
            type: cc.Node
        },
        Score:0,
        ScoreLable:{
            default:null,
            type:cc.Label
        },
    },
    //生命值变化
    HPChanger:function (change) {
  
        this.HP += change;
        if(this.HP > this.Option.HPMax){
            this.HP = this.Option.HPMax;
            console.log("生命值已满!");
        }      
        else if(this.HP <= 0){
            this.HP = 0;
            this.GameOver();
        }
        this.HPUI.getComponent("HPUI").SetHP(this.HP);
        console.log("当前生命值: " + this.HP);
    },
    // 加分
    AddScore(addn) {
        this.Score += addn;
        this.ScoreLable.string = "Score: " + this.Score;
    },
    GameOver:function () {
        console.log("你已经死了");
        cc.director.pause();
        this.GameStart = false;
        this.Menu.active = true;
    },

    InitiateGame:function () {
        this.HP = this.Option.HPMax / 2;
        this.HPChanger(0);
        this.Player.position = cc.v2(0,-830);
        this.Player.getComponent("Bacteria").ShootSpeed = cc.v2(0,0);
        this.GameStart = true;
        cc.director.resume();
        this.Initiate.InitiateCells(this.Initiate);
    },
    

    // LIFE-CYCLE CALLBACKS:

    onLoad () {

    },

    start () {
        cc.director.pause();
    },

    // update (dt) {},
});
